<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        li{
            list-style: none;
            line-height: 45px;
            border: 1px dashed #333;
            text-indent:10px;
        }
    </style>
</head>
<body>
    <button class="add">新增</button>
    <button class="remove">删除</button>
    <div class="list">
        <li class="item">01</li>
        <li class="item">02</li>
        <li class="item">03</li>
        <li class="item">04</li>
        <li class="item">05</li>
        <li class="item">06</li>
    </div>
</body>
<script>
    // HTMLCollection   document.getElementsByClassName()  document.getElementsByTagName() 方法获取的元素的集合  => 特征 会随着页面同类型/类名元素的增加或减少 自动更新集合 
    var list = document.getElementsByClassName("list")[0];
    var liList = list.getElementsByClassName("item");
    var liList = list.getElementsByTagName("li");
    console.log(liList);

    // NodeList    document.querySelectorAll() 方法获取的节点集合  => 一经获取,集合就不会再改变
    // var liList = document.querySelectorAll(".item");
    // var liList = document.querySelectorAll(".list li");
    // console.log(liList);

    
    var add = document.getElementsByClassName("add")[0];
    var remove = document.getElementsByClassName("remove")[0];
    add.onclick = function(){
        var li = document.createElement("li");
        li.className = "item";
        li.textContent = "我是新增的li";
        list.appendChild(li);
        console.log(liList);
    }

    remove.onclick = function(){
        var last = list.lastElementChild;
        if(last){
            list.lastElementChild.remove();
            console.log(liList);
        }
    }


</script>
</html>